package com.yundasys.lab02springbootstudy.postprocessor;

import com.yundasys.lab02springbootstudy.bean.BeanDemo;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.stereotype.Component;

/**
 * @PACKAGE_NAME: com.yundasys.lab02springbootstudy.postprocessor
 * @NAME: MyBeanDefinitionRegistryPostProcessor
 * @USER: jiangta
 * @DATE: 2023/1/30
 * @TIME: 2:59 下午
 * @PROJECT_NAME: springboot-labs
 */
@Component
public class MyBeanDefinitionRegistryPostProcessor implements BeanDefinitionRegistryPostProcessor {
    @Override
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
        System.out.println("MyBeanDefinitionRegistryPostProcessor: "+registry);

        // 向beanDefinitionMap中注册自定义的beanDefinition对象
        GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
        beanDefinition.setBeanClass(BeanDemo.class);
        registry.registerBeanDefinition("beanDemo",beanDefinition);
    }

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        System.out.println("MyBeanDefinitionRegistryPostProcessor: "+beanFactory);
    }
}
